test_programs += $(_installed_or_uninstalled_test_programs)
endif
-if !USE_LIBSOUP_OR_LIBSOUP3
-no-soup-for-you-warning:
- @echo "WARNING: $(PACKAGE) was built without libsoup, which is currently" 1>&2
- @echo "WARNING: required for many unit tests." 1>&2
- sleep 10
-check: no-soup-for-you-warning
-endif
-
# Unfortunately the glib test data APIs don't actually handle
# non-recursive Automake, so we change our code to canonically look
# for tests/ which is just a symlink when installed.
fi
}
+run_webserver() {
+ echo httpd=${OSTREE_HTTPD}
+ if test -z "${OSTREE_HTTPD:-}"; then
+ if test "$#" -gt 0; then
+ echo "fatal: unhandled arguments for webserver: $@" 1>&2
+ exit 1
+ fi
+ # Note this automatically daemonizes; close stdin to ensure it doesn't leak to the child.
+ ${test_srcdir}/webserver.py ${test_tmpdir}/httpd-port </dev/null &>/dev/null
+ echo "Waiting for webserver..."
+ while test '!' -f ${test_tmpdir}/httpd-port; do
+ sleep 0.5
+ done
+ else
+ ${OSTREE_HTTPD} --autoexit --log-file $(pwd)/httpd.log --daemonize -p ${test_tmpdir}/httpd-port "$@"
+ fi
+ port=$(cat ${test_tmpdir}/httpd-port)
+ echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
+}
+
# The original one; use setup_fake_remote_repo2 for newer code,
# down the line we'll try to port tests.
setup_fake_remote_repo1() {
mkdir ${test_tmpdir}/httpd
cd httpd
ln -s ${test_tmpdir}/ostree-srv ostree
- ${OSTREE_HTTPD} --autoexit --log-file $(pwd)/httpd.log --daemonize -p ${test_tmpdir}/httpd-port "$@"
- port=$(cat ${test_tmpdir}/httpd-port)
- echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
+ run_webserver "$@"
cd ${oldpwd}
export OSTREE="${CMD_PREFIX} ostree --repo=repo"
mkdir ${test_tmpdir}/httpd
cd httpd
ln -s ${test_tmpdir}/ostree-srv ostree
- ${OSTREE_HTTPD} --autoexit --log-file $(pwd)/httpd.log --daemonize -p ${test_tmpdir}/httpd-port $args
- port=$(cat ${test_tmpdir}/httpd-port)
- echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
- cd ${oldpwd}
+ run_webserver
+ cd ${oldpwd}
export OSTREE="${CMD_PREFIX} ostree --repo=repo"
}
shift
bootmode=$1
shift
- bootdir=${1:-usr/lib/modules/3.6.0}
+ bootdir=usr/lib/modules/3.6.0
+ if test "$#" -gt 0; then
+ bootdir=$1
+ shift
+ fi
oldpwd=`pwd`
mkdir ${test_tmpdir}/httpd
cd httpd
ln -s ${test_tmpdir} ostree
- ${OSTREE_HTTPD} --autoexit --daemonize -p ${test_tmpdir}/httpd-port
- port=$(cat ${test_tmpdir}/httpd-port)
- echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
+ run_webserver "$@"
cd ${oldpwd}
}
fi
}
+skip_without_ostree_httpd () {
+ if test -z "${OSTREE_HTTPD:-}"; then
+ skip "this test requires libsoup (ostree-trivial-httpd)"
+ fi
+}
+
skip_without_user_xattrs () {
if ! have_user_xattrs; then
skip "this test requires xattr support"
. $(dirname $0)/libtest.sh
+skip_without_ostree_httpd
setup_fake_remote_repo1 "archive" "" "--require-basic-auth"
echo '1..3'
. $(dirname $0)/libtest.sh
+skip_without_ostree_httpd
+
COMMIT_SIGN=""
if has_ostree_feature gpgme; then
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
. $(dirname $0)/libtest.sh
+skip_without_ostree_httpd
setup_fake_remote_repo1 "archive" "" "--force-range-requests"
echo '1..1'
set -euo pipefail
-echo '1..2'
-
. $(dirname $0)/libtest.sh
+skip_without_ostree_httpd
+echo '1..2'
+
V=$($CMD_PREFIX ostree --version | \
python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin)["libostree"]["Version"])')
--- /dev/null
+#!/usr/bin/env python3
+# Run a webserver on a random port, serving the current working directory.
+# The allocated port is written to the provided path
+import http.server
+from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
+import socket
+import sys
+import os
+import argparse
+import threading
+import time
+import contextlib
+
+def _get_best_family(*address):
+ infos = socket.getaddrinfo(
+ *address,
+ type=socket.SOCK_STREAM,
+ flags=socket.AI_PASSIVE,
+ )
+ family, ty, proto, canonname, sockaddr = next(iter(infos))
+ return family, sockaddr
+
+def run(port_path, HandlerClass=SimpleHTTPRequestHandler,
+ ServerClass=ThreadingHTTPServer,
+ protocol="HTTP/1.1", port=0, bind=None):
+ ServerClass.address_family, addr = _get_best_family(bind, port)
+ HandlerClass.protocol_version = protocol
+
+ server = ThreadingHTTPServer(addr, HandlerClass)
+
+ with server as httpd:
+ host, port = httpd.socket.getsockname()[:2]
+ with open(port_path + '.tmp', 'w') as f:
+ f.write(f'{port}\n')
+ os.rename(port_path + '.tmp', port_path)
+ print(f"Running on port {port}")
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ print("\nKeyboard interrupt received, exiting.")
+ sys.exit(0)
+
+def main():
+ # We automatically daemonize
+ pid = os.fork()
+ if pid > 0:
+ sys.exit(0)
+ os.setsid()
+ pid = os.fork()
+ if pid > 0:
+ sys.exit(0)
+ # code to spawn a thread and detect when the current working directory no longer exists, then exit
+ def watch_cwd(original_cwd):
+ while True:
+ try:
+ os.stat(original_cwd)
+ except FileNotFoundError:
+ sys.exit(0)
+ time.sleep(1)
+
+ original_cwd = os.getcwd()
+ watcher_thread = threading.Thread(target=watch_cwd, args=(original_cwd,))
+ watcher_thread.daemon = True
+ watcher_thread.start()
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument('port_path', metavar='PATH',
+ help='Write port used to this path ')
+ args = parser.parse_args()
+ run(args.port_path)
+
+if __name__ == '__main__':
+ main()